// run: $exec < input
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>

struct point
{
	double x, y;
};

struct line
{
	point a, b;
};

struct tline
{
	double a, b, c;
};

struct online
{
	point a;
	int dir;
	int index;
};

bool operator<(online const & a, online const & b)
{
	return a.a.x < b.a.x || (a.a.x == b.a.x && a.a.y < b.a.y);
}

int const maxn = 1100;
std::vector<online> on_line;
std::vector<point> points(maxn);
line l;
int n;

double const eps = 1e-6;

double xmult(point p1, point p2, point p0)
{
	return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}

bool same_side(point const & p1, point const & p2, line const & l)
{
	return xmult(l.a, p1, l.b) * xmult(l.a, p2, l.b) > eps;
}

point line_inter(tline const & l1, tline const & l2)
{
	point tmp;
	double a1 = l1.a, b1 = l1.b, c1 = l1.c, a2 = l2.a, b2 = l2.b, c2 = l2.c;

	if (std::fabs(b1) < eps) {
		tmp.x = -c1 / a1;
		tmp.y = (-c2 - a2 * tmp.x) / b2;
	} else {
		tmp.x = (c1 * b2 - b1 * c2) / (b1 * a2 - b2 * a1);
		tmp.y = (-c1 - a1 * tmp.x) / b1;
	}

	return tmp;
}

tline trans_tline(line const & l)
{
	tline tmp;
	tmp.a = l.a.y - l.b.y;
	tmp.b = l.b.x - l.a.x;
	tmp.c = l.a.x * l.b.y - l.a.y * l.b.x;
	return tmp;
}

bool dot_online(point const & a, line const & l)
{
	return std::fabs(xmult(l.a, a, l.b)) < eps;
}

double dis(point const & a, point const & b)
{
	return std::sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

int main()
{
	std::ios::sync_with_stdio(false);
	while (std::cin >> n) {
		on_line.clear();
		for (int i = 0; i < n; i++) std::cin >> points[i].x >> points[i].y;
		points[n] = points[0];
		std::cin >> l.a.x >> l.a.y >> l.b.x >> l.b.y;

		for (int i = 0; i < n; i++) {
			if (same_side(points[i], points[i + 1], l)) continue;
			if (dot_online(points[i], l) && dot_online(points[i + 1], l)) continue;
			line tmp;
			tmp.a = points[i]; tmp.b = points[i + 1];
			point inter = line_inter(trans_tline(tmp), trans_tline(l));
			int t = xmult(l.a, points[i + 1], l.b);
			int dir = (t > eps);
			if (!t) dir = xmult(l.a, points[i], l.b) < -eps;
			online tt;
			tt.a = inter;
			tt.dir = dir;
			tt.index = i;
			on_line.push_back(tt);
		}

		std::sort(on_line.begin(), on_line.end());

		/*
		for (int i = 0; i < (int)on_line.size(); i++) std::cout << on_line[i].a.x << ' ' << on_line[i].a.y <<
				" dir = " << on_line[i].dir << " index = " << on_line[i].index << '\n';
				*/

		double ans = 0;
		int d1 = on_line[0].dir;
		for (int i = 0; i < (int)on_line.size(); i++) {
			online o1 = on_line[i], o2 = on_line[i + 1];
			if (dot_online(o1.a, l) && dot_online(o2.a, l) && (o1.index == o2.index + 2 || o1.index + 2 == o2.index)) {
				ans += dis(o1.a, o2.a);
			} else {
				if (o1.dir == d1 && o2.dir == !d1) ans += dis(o1.a, o2.a);
			}
		}
		std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(3) << ans << '\n';
	}
}

